package com.tzs.controller;

import com.tzs.model.User;
import com.tzs.response.BaseResponse;
import com.tzs.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.*;


/**
 * 用户Controller
 *
 * @author Tanzs
 * @Date 2019/8/20
 */
@Api(value="用户controller",tags={"用户操作接口"})
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation(value = "获取所有用户信息",notes = "获取所用用户信息(分页查询)")
    @ApiImplicitParams({
           @ApiImplicitParam(name ="pageNo",value = "第几页",required=false, dataType = "int",paramType = "query"),
           @ApiImplicitParam(name="PageSize",value = "条数",required = false, dataType = "int",paramType = "query")
    })
    @ResponseBody
    @GetMapping(value = "/getAllUser")
    public BaseResponse getAllUser(@RequestParam(required = false,value = "pageNo",defaultValue = "1") int pageNo, @RequestParam(required = false,value = "PageSize",defaultValue = "10") int PageSize, User user){
        BaseResponse response=userService.getAllUser(pageNo,PageSize, user);
        return response;
    }

    @ApiOperation(value = "根据用户id删除用户信息",notes = "根据用户Id删除用户信息")
    @ApiImplicitParam(name = "ids",value = "用户id(可批量用,隔开)",required = true,dataType = "String", paramType = "path")
    @ResponseBody
    @DeleteMapping(value = "delUser/{ids}")
    public BaseResponse delUserById(@PathVariable String ids){
        BaseResponse response=userService.delUserById(ids);
        return response;
    }

    @ApiOperation(value = "新增用户信息",notes ="新增用户" )
    @ApiImplicitParam(name = "rid",value = "用户权限Id",required = true,dataType = "int",paramType = "form")
    @ResponseBody
    @PostMapping(value = "insert")
    public BaseResponse insertUser(User user, @RequestParam(value = "rid",defaultValue = "1")Integer rid){
        BaseResponse response=userService.insertUser(user,rid);
        return response;
    }

    @ApiOperation(value = "修改用户信息",notes = "修改用户信息")
    @ResponseBody
    @PutMapping("update")
    public BaseResponse updateUser(User user){
        BaseResponse response=userService.updateUser(user);
        return response;
    }

    @ApiOperation(value = "获取表格导出所需数据",notes = "获取Execel导出数据")
    @ResponseBody
    @GetMapping(value = "/getExecelList")
    public BaseResponse getExecelList(){
        BaseResponse response=userService.getExecelList();
        return response;
    }

    @ApiOperation(value = "测试",notes = "测试")
    @ResponseBody
    @GetMapping(value = "/test")
    public BaseResponse Test(){
        BaseResponse response=userService.Test();
        return response;
    }


}